ROCm: Add gfx950 (MI355X/CDNA4) to is_cdna() and include PR #4021 fixes#4050
ROCm: Add gfx950 (MI355X/CDNA4) to is_cdna() and include PR #4021 fixes#4050GoldenGrapeGentleman wants to merge 18 commits intounslothai:mainfrom
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
…x/warn-unsupported-lora-targets
MI355X (gfx950) has the same 1024-thread workgroup limit as MI300X (gfx942), but was missing from is_cdna(), causing all Triton kernels to use num_warps=32 (2048 threads) instead of 16 (1024 threads), resulting in OutOfResources crash. Also includes ROCm GPT-OSS BF16 routing and dequant buffer dtype fix from PR unslothai#4021 by @danielhanchen, cherry-picked for MI355X validation. Tested on: 8x AMD Instinct MI355X (gfx950), ROCm 7.1 - Vision RL GRPO (Qwen2.5-VL-7B): 5/5 steps - Code RL GRPO (gpt-oss-20b BF16): 20/20 steps - gpt-oss-120b GRPO: 5/5 steps (B200 OOM'd on this) - MoE expert LoRA + save_pretrained_merged: success
Summary of ChangesHello @GoldenGrapeGentleman, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances ROCm compatibility and stability by extending support to AMD Instinct MI355X (gfx950/CDNA4) GPUs, which directly addresses Triton kernel thread limit issues. It also integrates a suite of stability fixes from a previous pull request, focusing on robust model loading for GPT-OSS on HIP devices, refining dequantization logic, and proactively mitigating potential AITER-related problems on ROCm. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces support for the AMD Instinct MI355X (gfx950) GPU and incorporates several stability fixes for ROCm, which is a valuable enhancement. The changes are logical and well-implemented, particularly the safety improvements around dynamic code execution and buffer handling. I've identified a couple of areas with code duplication that could be refactored to improve long-term maintainability. Overall, this is a solid contribution that improves hardware support and the robustness of the library.
| elif DEVICE_TYPE == "hip": | ||
| SUPPORTS_BFLOAT16 = torch.cuda.is_bf16_supported() | ||
|
|
||
| def is_bf16_supported(): | ||
| return SUPPORTS_BFLOAT16 | ||
| elif DEVICE_TYPE == "xpu": | ||
| # torch.xpu.is_bf16_supported() does not have including_emulation | ||
| # set SUPPORTS_BFLOAT16 as torch.xpu.is_bf16_supported() | ||
| SUPPORTS_BFLOAT16 = torch.xpu.is_bf16_supported() | ||
|
|
||
| def is_bf16_supported(): | ||
| return SUPPORTS_BFLOAT16 |
There was a problem hiding this comment.
To improve maintainability and reduce code duplication, you can refactor this logic. The is_bf16_supported function is defined identically for both hip and xpu device types. Combining the elif blocks for hip and xpu and defining the function only once would make the code cleaner.
| elif DEVICE_TYPE == "hip": | |
| SUPPORTS_BFLOAT16 = torch.cuda.is_bf16_supported() | |
| def is_bf16_supported(): | |
| return SUPPORTS_BFLOAT16 | |
| elif DEVICE_TYPE == "xpu": | |
| # torch.xpu.is_bf16_supported() does not have including_emulation | |
| # set SUPPORTS_BFLOAT16 as torch.xpu.is_bf16_supported() | |
| SUPPORTS_BFLOAT16 = torch.xpu.is_bf16_supported() | |
| def is_bf16_supported(): | |
| return SUPPORTS_BFLOAT16 | |
| elif DEVICE_TYPE in ("hip", "xpu"): | |
| if DEVICE_TYPE == "hip": | |
| SUPPORTS_BFLOAT16 = torch.cuda.is_bf16_supported() | |
| else: # xpu | |
| # torch.xpu.is_bf16_supported() does not have including_emulation | |
| # set SUPPORTS_BFLOAT16 as torch.xpu.is_bf16_supported() | |
| SUPPORTS_BFLOAT16 = torch.xpu.is_bf16_supported() | |
| def is_bf16_supported(): | |
| return SUPPORTS_BFLOAT16 |
| ( | ||
| model_name, | ||
| load_in_4bit, | ||
| load_in_8bit, | ||
| load_in_fp8, | ||
| load_in_16bit, | ||
| quantization_config, | ||
| ) = _route_hip_gpt_oss_model( | ||
| model_name = model_name, | ||
| use_exact_model_name = use_exact_model_name, | ||
| load_in_4bit = load_in_4bit, | ||
| load_in_8bit = load_in_8bit, | ||
| load_in_fp8 = load_in_fp8, | ||
| load_in_16bit = load_in_16bit, | ||
| quantization_config = quantization_config, | ||
| kwargs = kwargs, | ||
| ) |
There was a problem hiding this comment.
This block of code for routing HIP GPT-OSS models is duplicated in FastModel.from_pretrained at lines 880-896. To improve maintainability and reduce redundancy, consider refactoring this logic into a shared helper method that both FastLanguageModel.from_pretrained and FastModel.from_pretrained can call. This would centralize the model routing logic, making future updates easier.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 41c5a9639f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if not lower_model_name.endswith("-bf16"): | ||
| if "120b" in lower_model_name: | ||
| model_name = "unsloth/gpt-oss-120b-BF16" | ||
| else: | ||
| model_name = "unsloth/gpt-oss-20b-BF16" |
There was a problem hiding this comment.
Restrict HIP GPT-OSS remap to canonical model IDs
_route_hip_gpt_oss_model rewrites matched names to unsloth/gpt-oss-20b-BF16/120b-BF16 based only on substring matching, so on HIP it can replace requested non-base models (e.g. unsloth/gpt-oss-safeguard-20b, which is a valid mapped ID in unsloth/models/mapper.py:1246-1252) and local checkpoint paths that include gpt-oss. In those cases the loader silently fetches different weights than the caller asked for, which can invalidate training/evaluation results.
Useful? React with 👍 / 👎.
Summary
Add AMD Instinct MI355X (gfx950 / CDNA4) support to
is_cdna()and include ROCm stability fixes from PR #4021 by @danielhanchen.Problem
is_cdna()only listed gfx940/941/942 (MI300 series). MI355X (gfx950, CDNA4) has the same 1024-thread workgroup limit but was missing, causing all Triton kernels to usenum_warps=32(2048 threads) instead of 16 (1024 threads):This blocked all training on MI355X.
Changes
"gfx950"tois_cdna()inunsloth/kernels/utils.py(+1 line)Verified on 8× AMD Instinct MI355X (gfx950), ROCm 7.1
cc @danielhanchen — this includes your PR #4021 changes, cherry-picked and validated on MI355X. The
is_cdna()fix is the additional piece needed for CDNA4.